/**
 * Created by gongxun on 16/10/27.
 */

var HallLoginResponseHandler = function(){
    var that = new GameResponseBase();

    that.handle = function (binary, msgid) {
        that.loadMessage(binary, msgid);

        var code = that.msg.code;
        if (code == 0){
            //登录成功
            mo.gameUserInfo.setUser(that.msg.user);

            //保存用户登录信息
            mo.fileHelper.setLoginInfo(that.msg.user.userid);

            //获取礼包
            mo.userMessage.setMsgIds([]);
            mo.userMessage.getUserMessageIds();

            //如果加入游戏成功就 发送deviceJson
            mo.gameUserInfo.sendUserDeviceJson();
        } else if (code == 1){
            // mo.showRoomMsgShow("登录失败，服务器内部错误", false);
        } else if (code == 2){
            // mo.showRoomMsgShow("登录失败", false);
        } else if (code == 3){
            // mo.showRoomMsgShow("该账号已经登录", false);
        } else if (code == 4){
            // mo.showRoomMsgShow("该账号正在游戏中，请稍后再试", false);
        }

        if (code == 0 && that.msg.tableno == null){
            //不在游戏内 拉入大厅
            mo.sceneHelper.intoHallLayer();
        }

        //通知
        mo.gameWebsocket.onLoginCallback(code == 0);

        //如果不再牌桌尝试拉入游戏
        if (that.msg.tableno == null){
            mo.gameUserInfo.tryJoinTable();
        }
    };

    return that;
};